-
Notifications
You must be signed in to change notification settings - Fork 170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(#947) IterableEnvelope only delegates and IterableOf has behaviour #1154
(#947) IterableEnvelope only delegates and IterableOf has behaviour #1154
Conversation
Job #1154 is now in scope, role is |
This pull request #1154 is assigned to @vzurauskas/z, here is why; the budget is 15 minutes, see §4; please, read §27 and when you decide to accept the changes, inform @llorllale/z (the architect) right in this ticket; if you decide that this PR should not be accepted ever, also inform the architect; this blog post will help you understand what is expected from a code reviewer; there will be no monetary reward for this job |
@vzurauskas ping? |
e754c90
to
2dc9623
Compare
Codecov Report
@@ Coverage Diff @@
## master #1154 +/- ##
============================================
- Coverage 89.35% 89.33% -0.03%
- Complexity 1588 1599 +11
============================================
Files 271 272 +1
Lines 3888 3899 +11
Branches 215 214 -1
============================================
+ Hits 3474 3483 +9
- Misses 379 381 +2
Partials 35 35
Continue to review full report at Codecov.
|
@victornoel Sorry, still fighting the ton of REV jobs in my agenda. A new option to limit them should be introduced soon, it should be better then. |
@0crat refuse |
@vzurauskas The user @vzurauskas/z resigned from #1154, please stop working. Reason for job resignation: Order was cancelled |
Tasks refusal is discouraged, see §6: -15 point(s) just awarded to @vzurauskas/z |
This pull request #1154 is assigned to @scristalli/z, here is why; the budget is 15 minutes, see §4; please, read §27 and when you decide to accept the changes, inform @llorllale/z (the architect) right in this ticket; if you decide that this PR should not be accepted ever, also inform the architect; this blog post will help you understand what is expected from a code reviewer; there will be no monetary reward for this job |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@victornoel I left a few comments
@@ -49,13 +47,7 @@ public Solid(final X... src) { | |||
* @param iterable The iterable | |||
*/ | |||
public Solid(final Iterable<X> iterable) { | |||
super( | |||
new NoNulls<>( | |||
new org.cactoos.scalar.Solid<>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@victornoel why remove NoNulls
and Solid
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@scristalli because it was useless, the tests passes without them: I think the NoNulls
is a remnant of the past and that the Solid
was only needed because IterableEnvelope
was taking a Scalar
before.
new org.cactoos.scalar.Sticky<Iterable<X>>( | ||
() -> { | ||
final Collection<X> temp = new LinkedList<>(); | ||
for (final X item : iterable) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@victornoel is it possible to refactor this part and use an object-oriented approach?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@scristalli I believe it's out of scope of the issue solved, you can open an issue in cactoos if you want. I tried to think about it, but it's not clear what is best between using ListOf
+ scalar.Sticky
, or directly list.Sticky
, etc. You can add this information in the issue you create for example.
*/ | ||
public final class IterableOf<X> extends IterableEnvelope<X> { | ||
@SuppressWarnings("PMD.OnlyOneConstructorShouldDoInitialization") | ||
public final class IterableOf<X> implements Iterable<X> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@victornoel what's the reason for implementing Iterable
now instead of keep extending IterableEnvelope
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@scristalli it was kind of explained in the description: the envelope does not contain any specific behaviour that is implemented by IterableOf
. IterableOf
is not a decorator on Iterable
, it's an implementation of Iterable
. I could have extended IterableEnvelope
, but I believe it would have been a design mistake semantically. Also, now that I think about it, it wouldn't have been possible to implement toString
, equals
and hashCode
if I was extending IterableEnvelope
.
2dc9623
to
e71c2ba
Compare
@scristalli I've pushed some change and answere your comments, thanks |
@llorllale I approve the changes |
* <p>There is no thread-safety guarantee. | ||
* | ||
* <p>This class implements {@link Scalar}, which throws a checked | ||
* {@link IOException}. This may not be convenient in many cases. To make |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@victornoel it's just an Exception
now
@victornoel I come here from llorllale/cactoos-matchers#135 I'm not sure about the consequences of transferring From a usability perspective, it's the difference between Existing way: // we get equals, hashcode and toString for free
public final MyIterable<T> extends IterableEnvelope<T>{
public MyIterable(final T ...elements) {
super(args);
}
} And your way: // we need IterableOf to get equals, hashcode and toString
public final MyIterable<T> extends IterableEnvelope<T>{
public MyIterable(final T ...elements) {
super(new IterableOf<>(args));
}
} Also, it's not clear why |
@llorllale First, let me remind you that there is a discussion in #947 that arrived to the conclusion that envelope should only delegates to wrapped object. Hence this PR. But I completely share the design decisions here, so let me try to explain them. To me: one class = one responsibility. An envelope, by its name, is something whose responsibility is to envelope. Actually I see it as a pattern, it doesn't implement behaviour, it helps implementing behaviour in other class by easing the delegation of implementation to another class. As in your second example. The problem with it, is that it's useless as an example, you could have used directly
You are right, it doesn't. I could introduce a class named Then We actually could also implement See there already you have two different implementation of the same behaviour: |
@llorllale oups, forgot to ping you in my previous answer, I edited it :) |
@llorllale you will notice I did a mixup in my head between |
@llorllale it's done, sorry again for the confusion |
@llorllale two more points:
|
@llorllale can we get some conlusion on this and get it merged if it's ok :) |
@victornoel I appreciate your insights but I'm afraid that discussion is not over yet. You decide - you can either modify this PR or close it for now. |
@llorllale ok, what would you want me to change then so that this can be merged? |
This pull request #1154 is assigned to @fabriciofx/z, here is why; the budget is 15 minutes, see §4; please, read §27 and when you decide to accept the changes, inform @paulodamaso/z (the architect) right in this ticket; if you decide that this PR should not be accepted ever, also inform the architect; this blog post will help you understand what is expected from a code reviewer; there will be no monetary reward for this job |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@victornoel I agree with the new design. Can you fix the minor corrections.
*/ | ||
public IterableEnvelope(final Scalar<Iterable<X>> scalar) { | ||
this.iterable = new Unchecked<>(scalar); | ||
public IterableEnvelope(final Iterable<X> wrapped) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@victornoel The parameter's name and attribute must be different. Please, can you change it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fabriciofx why should they be different? I'm not clear on the rational behind that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@victornoel it's a bad practice because is harder than read (different name is easier). Who said it? Yegor and if you pay attention, you'll see these names are (or should be) different ia cactoos' classes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fabriciofx thx, didn't know that, I will change them, the argument is convincing :) btw do you known if there is a blog post about that matter somewhere, I would be interested on reading about it more!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@victornoel I don't remember if there is a blog post about it, but once I pushed a PR and Yegor alert me about it...
*/ | ||
public Mapped(final Func<T, U> func, final Scalar<T> scalar) { | ||
this.origin = scalar; | ||
this.func = func; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@victornoel The parameter's name and attribute must be different. Please, can you change it?
final IterableOf<Integer> iterable = new IterableOf<>(1, 2); | ||
new Assertion<>( | ||
"Must have equal hashCode for Iterables with equal content", | ||
iterable.hashCode(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@victornoel Move new IterableOf<>(1, 2)
to this line.
final IterableOf<Integer> iterable = new IterableOf<>(1, 2); | ||
new Assertion<>( | ||
"Must be equal to itself", | ||
iterable, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@victornoel Move new IterableOf<>(1, 2)
to this line.
final IterableOf<Integer> iterable = new IterableOf<>(1, 2); | ||
new Assertion<>( | ||
"Must be equal to Iterable with the same elements", | ||
iterable, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@victornoel Move new IterableOf<>(1, 2)
to this line.
final IterableOf<Integer> iterable = new IterableOf<>(); | ||
new Assertion<>( | ||
"Empty Iterable must be equal to empty Iterable", | ||
iterable, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@victornoel Move new IterableOf<>()
to this line.
e71c2ba
to
d89f644
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@victornoel please, check it out.
@paulodamaso please, check it out why travis and appveyour fail. I cant' approve a PR that fails build. |
5ff830b
to
2a892cb
Compare
@fabriciofx I've rebased on master for the build to pass and applied the change you asked for. It should be alright know |
2a892cb
to
4325d95
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@victornoel just more few minor corrections and after that, it'll be free to merge.
@Test | ||
public void notEqualsToObjectOfAnotherType() { | ||
new Assertion<>( | ||
"Must not equal to object of another type", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@victornoel please, change "Must.."
for `"must.." and all strings below.
@Test | ||
public void equalToEmptyIterable() { | ||
new Assertion<>( | ||
"Empty Iterable must be equal to empty Iterable", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@victornoel The same here: "empty..."
.
a505301
to
2379aa8
Compare
@fabriciofx it's done, thanks |
@Test | ||
public void transformsScalar() throws Exception { | ||
new Assertion<>( | ||
"Must transform scalar", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@victornoel you forgot here...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fabriciofx damned, sorry, now it's fixed
2379aa8
to
b092754
Compare
@victornoel it seems fine to me. Congratulations for this nice PR! @paulodamaso can you merge it, please? |
@rultor merge |
@paulodamaso OK, I'll try to merge now. You can check the progress of the merge here |
@paulodamaso Done! FYI, the full log is here (took me 15min) |
@paulodamaso/z all |
The job #1154 is now out of scope |
Payment to |
This is for #947.
I started with
IterableEnvelope
and added todos forListEnvelope
andCollectionEnvelope
.I had to:
IterableOf
. I believe it makes sense for this to be.IterableOf
when extendingIterableEnvelope
to get the same behaviour.IterableOf
now publicly takes aScalar<Iterator>
since it is the root of its behaviourScalar
namedMapped
to simplify implementation in some placesIt's a bit big, but I feel like it had to happen because of the high number of classes extending
IterableEnvelope
.